package com.lmh.ymw.util.httpapidemo;

import com.lmh.ymw.util.httpapidemo.common.Config;
import com.lmh.ymw.util.httpapidemo.common.HttpUtil;

import java.net.URLEncoder;
import java.util.Random;

/**
 * 短信API发送
 * @author JiangPengFei
 * @version $Id: javaHttpNewApiDemo, v 0.1 2019/1/23 11:42 JiangPengFei Exp $$
 */
public class SmsApiHttpSendTest {

	/**
	 * 短信发送(验证码通知，会员营销)
	 * 接口文档地址：http://www.danmi.com/developer.html#smsSend
	 */
	public void execute(String sj,String str) throws Exception{
		StringBuilder sb = new StringBuilder();
		sb.append("accountSid").append("=").append(Config.ACCOUNT_SID);
		sb.append("&to").append("=").append(sj);
		sb.append("&param").append("=").append(URLEncoder.encode(str,"UTF-8"));
		sb.append("&templateid").append("=").append("274948");
		/*sb.append("&smsContent").append("=").append( URLEncoder.encode("【旦米科技】您的验证码为123456，该验证码5分钟内有效。请勿泄漏于他人。","UTF-8"));*/
		String body = sb.toString() + HttpUtil.createCommonParam(Config.ACCOUNT_SID, Config.AUTH_TOKEN);
		String result = HttpUtil.post(Config.BASE_URL, body);
		System.out.println(result);

	}

	public static String yzm(String sj) {
		Random random=new Random();
		String str="";
		for(int i=0;i<4;i++) {
			int n=random.nextInt(4);
			str+=n;
		}
		SmsApiHttpSendTest am = new SmsApiHttpSendTest();
		try {
			am.execute(sj,str);
		}catch (Exception e){
			e.printStackTrace();
		}
		return str;
	}
}
